﻿using System.Collections.Generic;

namespace DinletBilsin
{
    class HitCounter
    {
        public Dictionary<int, int> counter = new Dictionary<int, int>();
        public HitCounter()
        {

        }
        /// <summary>
        /// İlgili ID değerindeki sayaç verilen miktar artırılır.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="count"></param>
        public void Update(int key, int count)
        {
            if (counter.ContainsKey(key))
                counter[key] += count;
            else
                counter[key] = count;
        }
        public void Update(List<KeyValuePair<int, int>> results)
        {
            foreach (KeyValuePair<int, int> result in results)
            {
                Update(result.Value, result.Key);
            }
        }
        public int GetMaxID(ref int score)
        {
            int maxID = -1;
            int maxCount = -1;
            foreach (KeyValuePair<int, int> item in counter)
            {
                if (item.Value > maxCount)
                {
                    maxID = item.Key;
                    maxCount = item.Value;
                }
            }
            score = maxCount;
            return maxID;
        }
    }
}
